﻿using Gufa.Entity;
using Gufa.IServices;
using Gufa.WebAPI.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;


namespace Gufa.WebAPI.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ExperienceController : ControllerBase
    {
        private readonly IAwardService awardService;
        private readonly IExperienceService experienceService;
        public ExperienceController(IAwardService awardService, IExperienceService experienceService)
        {
            this.awardService = awardService;
            this.experienceService = experienceService;
        }

        [HttpGet]
        public async Task<IActionResult> GetAwardInfos()
        {
            List<Award> awards = await awardService.LoadEntities(a => a.DelFlag == 0).ToListAsync();
            ApiResult<List<Award>> result;

            if (awards != null)
            {
                if (awards.Count > 0)
                {
                    result = new ApiResult<List<Award>>()
                    {
                        Success = true,
                        Data = awards,
                        Message = "查询奖项信息成功"
                    };
                }
                else
                {
                    result = new ApiResult<List<Award>>() { Success = true, Data = null, Message = "未查询到奖项信息" };
                }
            }
            else
            {
                result = new ApiResult<List<Award>> { Success = false, Data = null, Message = "查询结果为null，请检查后端代码" };
            }

            return Ok(result);
        }

        [HttpGet("experience")]
        public async Task<IActionResult> GetExperience()
        {
            List<Experience> experiences = await experienceService.LoadEntities(e => e.DelFlag == 0).Include(e => e.Responsibilities).Include(e => e.ProjectInfos).ToListAsync();

            ApiResult<List<Experience>> result;

            if (experiences != null)
            {
                if (experiences.Count > 0)
                {
                    result = new ApiResult<List<Experience>>()
                    {
                        Success = true,
                        Data = experiences,
                        Message = "查询工作经验信息成功"
                    };
                }
                else
                {
                    result = new ApiResult<List<Experience>>() { Success = true, Data = null, Message = "未查询到工作经验信息" };
                }
            }
            else
            {
                result = new ApiResult<List<Experience>> { Success = false, Data = null, Message = "查询结果为null，请检查后端代码" };
            }

            return Ok(result);
        }
    }
}
